package com.zjw.controller;


import com.zjw.annotation.domain.ResponseResult;
import com.zjw.annotation.domain.entity.Comment;
import com.zjw.enums.AppHttpCodeEnum;
import com.zjw.exception.SystemException;
import com.zjw.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 评论控制器
 *
 * @author LKZY
 * @date 2023/12/14 18:44
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 评论列表
     *
     * @param articleId 文章 ID
     * @param pageNum   页码
     * @param pageSize  页面大小
     * @return {@link ResponseResult}
     */
    @GetMapping("/commentList")
    public ResponseResult commentList(Long articleId,
                                      Integer pageNum,
                                      Integer pageSize){
        return commentService.commentList(articleId, pageNum, pageSize);
    }

    /**
     * 友链评论列表
     *
     * @param pageNum  页码
     * @param pageSize 页面大小
     * @return {@link ResponseResult}
     */
    @GetMapping("/linkCommentList")
    public ResponseResult linkCommentList( Integer pageNum,
                                      Integer pageSize){
        return commentService.linkListCommentList(pageNum, pageSize);
    }


    /**
     * 保存评论
     *
     * @param comment 评论
     * @return {@link ResponseResult}
     */
    @PostMapping
    public ResponseResult saveComment(@RequestBody Comment comment){
        if(!StringUtils.hasText(comment.getContent())){
            throw new SystemException(AppHttpCodeEnum.TEXT_ISNULL);
        }
        return commentService.saveComment(comment);
    }

}
